{{#if (eq runtime "workers")}}
import { PrismaClient } from "../prisma/generated/client";
import { env } from "cloudflare:workers";

{{#if (eq dbSetup "planetscale")}}
import { PrismaPlanetScale } from "@prisma/adapter-planetscale";

const adapter = new PrismaPlanetScale({ url: env.DATABASE_URL || "" });
const prisma = new PrismaClient({ adapter });
{{else}}
import { PrismaMariaDb } from "@prisma/adapter-mariadb";

const databaseUrl: string = env.DATABASE_URL || "";
const url: URL = new URL(databaseUrl);
const connectionConfig = {
  host: url.hostname,
  port: parseInt(url.port || "3306"),
  user: url.username,
  password: url.password,
  database: url.pathname.slice(1),
};

const adapter = new PrismaMariaDb(connectionConfig);
const prisma = new PrismaClient({ adapter });
{{/if}}

export default prisma;
{{else}}
import { PrismaClient } from "../prisma/generated/client";

{{#if (eq dbSetup "planetscale")}}
import { PrismaPlanetScale } from "@prisma/adapter-planetscale";

const adapter = new PrismaPlanetScale({ url: process.env.DATABASE_URL || "" });
const prisma = new PrismaClient({ adapter });
{{else}}
import { PrismaMariaDb } from "@prisma/adapter-mariadb";

const databaseUrl: string = process.env.DATABASE_URL || "";
const url: URL = new URL(databaseUrl);
const connectionConfig = {
  host: url.hostname,
  port: parseInt(url.port || "3306"),
  user: url.username,
  password: url.password,
  database: url.pathname.slice(1),
};

const adapter = new PrismaMariaDb(connectionConfig);
const prisma = new PrismaClient({ adapter });
{{/if}}

export default prisma;
{{/if}}